package com.aboo.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.aboo.constant.CommonConstant;
import com.aboo.po.BasePO;
import com.aboo.po.personnel.EmployeePO;
import com.aboo.service.personnel.IEmployeeService;
import com.aboo.util.DateUtil;

public class TestServlet extends HttpServlet {

	private static final long serialVersionUID = -8825666334747140718L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html");
		PrintWriter pw = resp.getWriter();
		pw.println("Hello World!");

		/*
		HttpSession session = req.getSession();
		ApplicationContext ctx = WebApplicationContextUtils
				.getWebApplicationContext(session.getServletContext());
		IEmployeeService employeeService = (IEmployeeService) ctx
				.getBean("employeeService");
		EmployeePO po1 = new EmployeePO();
		po1.setName("Music");
		po1.setSex(CommonConstant.SEX_MALE);
		po1.setBirthday(DateUtil.getDate(1925, 1, 5));
		po1.setSex(CommonConstant.SEX_UNKNOW);
		po1.setSalary(new BigDecimal(5688.00));
		po1.setInDate(DateUtil.getDate(1987, 3, 9));
		po1.setOutDate(null);
		po1.setMatureDate(DateUtil.getDate(1999, 9, 9));

		EmployeePO po2 = new EmployeePO();
		po2.setName("Color");
		po2.setSex(CommonConstant.SEX_MALE);
		po2.setBirthday(DateUtil.getDate(1944, 2, 8));
		po2.setSex(CommonConstant.SEX_FEMALE);
		po2.setSalary(new BigDecimal(8092.00));
		po2.setInDate(DateUtil.getDate(1979, 8, 23));
		po2.setOutDate(null);
		po2.setMatureDate(DateUtil.getDate(1999, 2, 1));

		EmployeePO po3 = new EmployeePO();
		po3.setName("Singer");
		po3.setSex(CommonConstant.SEX_MALE);
		po3.setBirthday(DateUtil.getDate(1945, 4, 3));
		po3.setSex(CommonConstant.SEX_MALE);
		po3.setSalary(new BigDecimal(6493.00));
		po3.setInDate(DateUtil.getDate(2009, 2, 29));
		po3.setOutDate(null);
		po3.setMatureDate(DateUtil.getDate(2012, 12, 28));

		List<BasePO> list = new ArrayList<BasePO>();
		list.add(po1);
		list.add(po2);
		list.add(po3);
		employeeService.save(list);
		*/
		
		pw.println("Save OK!");
		pw.close();
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}

}
